# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='sd_notify'
pkgname="ruby-${_gemname}"
pkgver=0.1.1
pkgrel=2
pkgdesc="Pure Ruby implementation of systemd's sd_notify(3)"
arch=('any')
url='https://github.com/agis/ruby-sdnotify'
license=('MIT')
depends=('ruby')
checkdepends=('ruby-minitest')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${_gemname}-v${pkgver}.tar.gz")
sha512sums=('84c1de42f1ba82e58a2091bf508d86ba5755b655b05b386514c67e0c00f2b8fe0d875bdbdce21fdafc0d128b28cd112965cdb9024d56fa1bbe3148c98d1591e4')

prepare() {
  cd "${srcdir}/ruby-sdnotify-${pkgver}"

  # drop useless dependencies
  sed --in-place '/rubocop/d' "${_gemname}.gemspec"
}

build() {
  cd "${srcdir}/ruby-sdnotify-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/ruby-sdnotify-${pkgver}"
  ruby -Ilib:test test/*
}

package() {
cd "${srcdir}/ruby-sdnotify-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md CHANGELOG.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
 }
